Machine Learning with Scala Quick Start Guide by Md. Rezaul Karim

Machine Learning with Scala Quick Start Guide by Md. Rezaul Karim

Author:Md. Rezaul Karim [Md. Rezaul Karim]
Language: eng
Format: epub
Tags: COM037000 - COMPUTERS / Machine Theory, COM018000 - COMPUTERS / Data Processing, COM062000 - COMPUTERS / Data Modeling and Design
Publisher: Packt
Published: 2019-04-30T21:09:52+00:00


However, based on the preceding prediction DataFrame, it is really difficult to guess the classification's accuracy. But in the second step, the evaluation is done using BinaryClassificationEvaluator as follows:

val accuracy = evaluator.evaluate(predictions)

println("Classification accuracy: " + accuracy)

This will provide an output with an accuracy value:

Accuracy: 0.8441663599558337

So, we get about 84% classification accuracy from our binary classification model. Just like with SVM and LR, we will observe the area under the precision-recall curve and the area under the receiver operating characteristic (ROC) curve based on the following RDD, which contains the raw scores on the test set:

val predictionAndLabels = predictions

.select("prediction", "label")

.rdd.map(x => (x(0).asInstanceOf[Double], x(1)

.asInstanceOf[Double]))

The preceding RDD can be used for computing the previously mentioned two performance metrics:

val metrics = new BinaryClassificationMetrics(predictionAndLabels)

println("Area under the precision-recall curve: " + metrics.areaUnderPR)

println("Area under the receiver operating characteristic (ROC) curve: " + metrics.areaUnderROC)

In this case, the evaluation returns 84% accuracy but only 67% precision, which is much better than that of SVM and LR:

Area under the precision-recall curve: 0.6665988000794282

Area under the receiver operating characteristic (ROC) curve: 0.8441663599558337

Then, we calculate some more metrics, for example, false and true positive, and false and true negative, as these predictions are also useful to evaluate the model's performance:

val TC = predDF.count() //Total count



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.